import request from '@/utils/request';
import type { Page, Role } from '@/type/RoleType';
import type { ResponseType } from '@/type/ResponseType';


enum Enum {
  fetchRoleListAPI = '/sys/role',
  deleteRoleAPI = '/sys/role',
  addRoleAPI = '/sys/role',
  findRoleAPI = '/sys/role',
  updateRoleAPI = '/sys/role',
  assignRolePermissionAPI = '/sys/role/assignPrem',
  fetchEnabledRoleListAPI = '/sys/role/list/enabled'
}

/**
 * @description 获取-分页查询角色列表
 * */
export const fetchRoleListAPI = (params: Page) => request.get<{ row: Role[], total: number }, ResponseType<{ rows: Role[], total: number }>>(`${Enum.fetchRoleListAPI}`, { params });

/**
 * @description 删除-角色的接口
 * */
export const deleteRoleAPI = (id: number) => request.delete<null, ResponseType<null>>(`${Enum.deleteRoleAPI}/${id}`);

/**
 * @description 添加-角色的接口
 * */
export const addRoleAPI = (data: Role) => request.post<Role, ResponseType<Role>>(Enum.addRoleAPI, data);

/**
 * @description 获取-角色详情的接口
 * */
export const findRoleAPI = (id: number) => request.get<Role, ResponseType<Role>>(`${Enum.findRoleAPI}/${id}`);

/**
 * @description 修改-角色详情的接口
 * */
export const updateRoleAPI = (data: Role) => request.put<null, ResponseType<null>>(`${Enum.updateRoleAPI}/${data.id}`, data);

/**
 * @description 分配权限-角色的接口
 * */
export const assignRoleAPI = (id: number, permIds: number[]) => request.put<null, ResponseType<null>>(Enum.assignRolePermissionAPI, { id, permIds });

/**
 * @description 获取-已启用的角色列表
 * */

export const fetchEnabledRoleListAPI = () => request.get<{ id: number, name: string }, ResponseType<{ id: number, name: string }[]>>(Enum.fetchEnabledRoleListAPI);
